package com.runa.rccprotocol.dto.debao;

import com.runa.persistence.DateUtil;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.analysis.debao.DeBao2Analysis;
import lombok.Data;

import java.util.Date;

/**
 * 2024/10/11 17:32
 * zhangYB
 */
@Data
public class DeBaoInfo {

    private byte[] readTime;

    private byte factoryCode;


    public DeBaoInfo(byte[] readTime, byte factoryCode) {
        this.readTime = readTime;
        this.factoryCode = factoryCode;
    }

    public boolean expired(int hour) {
        Date date = DateUtil.stringToDate(ByteUtil.byteToHexStringFlip(readTime, 0, readTime.length), "yyMMddHHmm");
        if (System.currentTimeMillis() - date.getTime() > 1000 * 60 * 60 * hour) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
//        String s = "0016121024";
        String s = "0012121024";
        DeBaoInfo deBaoInfo = new DeBaoInfo(ByteUtil.hexStringToByte(s), (byte)0x02);
        boolean expired = deBaoInfo.expired(1);
        System.out.println(expired);

        DeBaoRequestData requestData = new DeBaoRequestData("103621362");
        requestData.readByTime(deBaoInfo.getReadTime(), deBaoInfo.getFactoryCode(), 3);
        System.out.println(ByteUtil.byteToHexString(requestData.getData()));

        s = "685A015A01688862137A28020D600401401B00121210240301EEEEEEEEEEEEEEEEEEEEEEEEEEEE17EEEEEEEE35EEEEEEEE2CEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE00000100000000000000000000000000000000EE0000000000008516";
        byte[] bytes = ByteUtil.hexStringToByte(s);
        DeBao2Analysis deBao2Analysis = new DeBao2Analysis();
        int fill = deBao2Analysis.fill(bytes, bytes.length, null);


    }

}
